package structure.algorithm.leetcode;

public class LengthOfLongestSubstring {
    public int lengthOfLongestSubstring(String s) {
        StringBuilder sb = new StringBuilder();
        int a = 0;
        for (int b = 0; b < s.length(); b++) {
            char c = s.charAt(b);
            if (b == 0) {
                sb.append(c);
                a = 1;
                continue;
            }
            for (int d = 0; d < sb.length(); d++) {
                if (sb.charAt(d) == c) {
                    sb.delete(0, d + 1);
                    sb.append(c);
                    break;
                }
                if (d == sb.length() - 1 && c != sb.charAt(d)) {
                    sb.append(c);
                    if (a < sb.length()) {
                        a = sb.length();
                    }
                    break;
                }
            }
        }
        return a;
    }
}
